/**
 * ...
 * @author Franco Ponticelli
 */

package uform.property;

class LimitedIntPropertyDecorator extends PropertyDecorator<Null<Int>>
{
	public var max(default, setMax) : Null<Int>;
	public var min(default, setMin) : Null<Int>;
	
	function setMax(value : Null<Int>)
	{
		max = value;
		set(get());
		return max;
	}
	
	function setMin(value : Null<Int>)
	{
		min = value;
		set(get());
		return min;
	}
	
	override function set(value : Null<Int>) : IProperty<Null<Int>>
	{
		if (value != null)
		{
			if (max != null && value > max)
			{
				value = max;
			} else if (min != null && value < min)
			{
				value = min;
			}
		}
		decorated.set(value);
		return this;
	}
}